import React from 'react'
import axios from 'axios'
import { render } from 'react-dom'

// redux
import { createStore, applyMiddleware, compose, combineReducers } from 'redux'
import thunk from 'redux-thunk'
import { Provider } from 'react-redux'
import createHistory from 'history/createHashHistory'
import { ConnectedRouter, routerReducer, routerMiddleware } from 'react-router-redux'
import reducer from 'model/index'

// config
import VConsole from 'vconsole'
import 'moment/locale/zh-cn'
// import checkDevice from './config/device'
import axiosInterceptor from './config/axios'
import login from './config/login'
import registerServiceWorker from './registerServiceWorker'

// app
import App from './app'

// style
import 'less/index.less'

const history = createHistory()

const store = createStore(combineReducers({
  ...reducer,
  router: routerReducer
}), compose(
  applyMiddleware(thunk, routerMiddleware(history)),
  window.devToolsExtension ? window.devToolsExtension() : f => f
))
// checkDevice(store)
axiosInterceptor(store)
// login(store)

render(
  <Provider store = { store }>
    <ConnectedRouter history = { history }>
      <App />
    </ConnectedRouter>
  </Provider>,
  document.getElementById('root')
)

registerServiceWorker()
// new VConsole()
